package com.xxgc.eow.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaIgnore;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import com.xxgc.eow.result.Result;

import java.time.LocalDateTime;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.xxgc.eow.service.IPostaskService;
import com.xxgc.eow.entity.Postask;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 职位要求表 前端控制器
 * </p>
 *
 * @author Mr.Abel
 * @since 2023-05-23
 */
@Tag(name = "职位要求表")
@RestController
@RequestMapping("/postask")
public class PostaskController {

    @Resource
    private IPostaskService postaskService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "查询所有接口", description = "查询职位要求表所有数据")
    @SaIgnore
    @GetMapping
    public Result<List<Postask>> findAll() {
        return Result.ok(postaskService.getALl());
    }

    /**
     * 根据id查询数据接口
     * @param postId
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "根据postId查询数据接口", description = "通过postId查询")
    @Parameters({
            @Parameter(name = "postId",description = "postId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/{postId}")
    public Result<List<Postask>> findOne(@PathVariable Integer postId) {
        return Result.ok(postaskService.getALlByPostId(postId));
    }

//    /**
//     * 分页查询接口
//     * @param pageNum
//     * @param pageSize
//     * @return
//     */
//    @ApiOperationSupport(author = "Mr.Abel")
//    @Operation(summary = "分页查询接口", description = "分页查询")
//    @Parameters({
//            @Parameter(name = "pageNum",description = "页码",example="1",required = true,in=ParameterIn.QUERY),
//            @Parameter(name = "pageSize",description = "每页多少条",example="10",required = true,in=ParameterIn.QUERY)
//    })
//    @SaIgnore
//    @GetMapping("/page")
//    public Result<Page<Postask>> findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize) {
//        QueryWrapper<Postask> queryWrapper = new QueryWrapper<>();
//        return Result.ok(postaskService.page(new Page<>(pageNum, pageSize), queryWrapper));
//    }

    /**
     * 新增接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "新增接口", description = "新增接口")
    @SaIgnore
    @PostMapping("/save")
    public Result save(@RequestBody Postask postask) {
        postaskService.addPostAsk(postask);
        return Result.ok();
    }

    /**
     * 更新接口
     * @param
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "更新接口", description = "根据旧的askId和postId")
    @SaIgnore
    @PostMapping("/update")
    public Result update(@RequestBody Postask postask,int oldaskId) {
        if(postask.getCreateTime() == null ){
            postask.setCreateTime(LocalDateTime.now());
        }
        postaskService.updatPostAsk(postask,oldaskId);
        return Result.ok();
    }

    /**
     * 删除接口
     * @param postid
     * @return
     */
    @ApiOperationSupport(author = "Mr.Abel")
    @Operation(summary = "删除接口", description = "通过postId 和 askId删除")
    @Parameters({
            @Parameter(name = "postid",description = "postid",required = true,in=ParameterIn.QUERY),
            @Parameter(name = "askId",description = "askId",required = true,in=ParameterIn.QUERY)
    })
    @SaIgnore
    @GetMapping("/del")
    public Result delete(@Parameter Integer postid ,@Parameter int askId) {
        Postask postask = new Postask();
        postask.setAskTypeId(askId);
        postask.setPostId(postid);
        postask.setDestroyTime(LocalDateTime.now());
        postask.setTip(1);
        postaskService.delPostAsk(postask);
        return Result.ok();
    }

//    /**
//     * 批量删除接口
//     * @param ids
//     * @return
//     */
//    @ApiOperationSupport(author = "Mr.Abel")
//    @Operation(summary = "批量删除接口", description = "批量删除接口")
//    @SaIgnore
//    @PostMapping("/del/batch")
//    public Result deleteBatch(@RequestBody List<Integer> ids) {
//        postaskService.removeByIds(ids);
//        return Result.ok();
//    }
}